-
-
Notifications
You must be signed in to change notification settings - Fork 590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use the last olm session that got a message #776
Conversation
Tests now failing because of lack of new olm - looks like there are still issues on node 11 |
* Start a new Olm sessions with a device when we get an undecryptable message on it. * Send a dummy message on that sessions such that the other end knows about it. * Re-send any outstanding keyshare requests for that device. Also includes a unit test for megolm that isn't very related but came out as a result anyway. Includes #776 Fixes element-hq/element-web#3822
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, other than a typo, a minor performance tweak, and pending the question of whether the timestamp should be stored in olm or separately
src/crypto/OlmDevice.js
Outdated
return a.sessionId < b.sessionId ? -1 : 1; | ||
} | ||
}); | ||
return sessionInfos[sessionInfos.length - 1].sessionId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looping through the sessionInfos array, and keeping track of the sessionId with the smallest timestamp/sessionId is approximately the same number of lines of code, and faster (O(n) rather than O(n log n)). i.e.
let idxOfMin = 0;
for (i = 1; i < sessionInfos.length; i++) {
if (sessionInfos[i].lastReceivedMessageTs < sessionInfos[idxOfMin].lastReceiveMessageTs
|| (sessionInfos[i].lastReceivedMessageTs === sessionInfos[idxOfMin].lastReceiveMessageTs
&& sessionInfos[i].sessionId < sessinInfos[idxOfMin].sessionId)) {
idxOfMin = i;
}
return sessionInfos[idxOfMin].sessionId;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I was reluctant to bother changing it since it was already a sort, but fair enough
src/crypto/OlmDevice.js
Outdated
@@ -509,6 +509,8 @@ OlmDevice.prototype.createInboundSession = async function( | |||
this._storeAccount(txn, account); | |||
|
|||
const payloadString = session.decrypt(messageType, ciphertext); | |||
// this counts as an received message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/an/a/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm other than a couple typos
results[cursor.value.sessionId] = cursor.value.session; | ||
results[cursor.value.sessionId] = { | ||
session: cursor.value.session, | ||
lastReceivedMessagets: cursor.value.lastReceivedMessageTs, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the case changed here (lastReceivedMessagets vs lastReceivedmessageTs)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, good spot
func(getReq.result.session); | ||
func({ | ||
session: getReq.result.session, | ||
lastReceivedMessagets: getReq.result.lastReceivedMessageTs, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and a couple more typos
src/crypto/OlmDevice.js
Outdated
// Pretend we've received a message at this point, otherwise | ||
// if we try to send a message to the device, it won't use | ||
// this session (storing the creation time separately would | ||
// make the pickle longer and would not be useful otherwise). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not stored in the pickle any more
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ooh, yep
src/crypto/OlmDevice.js
Outdated
this._saveSession(theirDeviceIdentityKey, session, txn); | ||
const sessionInfo = { | ||
session, | ||
// this counts as an received message: set last received message time |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/an/a/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ptal!
src/crypto/OlmDevice.js
Outdated
// Pretend we've received a message at this point, otherwise | ||
// if we try to send a message to the device, it won't use | ||
// this session (storing the creation time separately would | ||
// make the pickle longer and would not be useful otherwise). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ooh, yep
src/crypto/OlmDevice.js
Outdated
return a.sessionId < b.sessionId ? -1 : 1; | ||
} | ||
}); | ||
return sessionInfos[sessionInfos.length - 1].sessionId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I was reluctant to bother changing it since it was already a sort, but fair enough
results[cursor.value.sessionId] = cursor.value.session; | ||
results[cursor.value.sessionId] = { | ||
session: cursor.value.session, | ||
lastReceivedMessagets: cursor.value.lastReceivedMessageTs, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, good spot
Implements matrix-org/matrix-spec-proposals#1596
For element-hq/element-web#3822
Requires https://github.com/matrix-org/olm-backup/pull/77 (+release)